package com.triones.api.controller.api.interlace;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.interlace.bo.InterlaceEstimateQuoteBO;
import com.triones.api.entity.interlace.bo.InterlaceKycBO;
import com.triones.api.entity.interlace.bo.InterlaceTransfersFeeAndQuotaBO;
import com.triones.api.entity.interlace.bo.request.UploadFileRequest;
import com.triones.api.entity.interlace.dto.InterlaceEstimateQuoteDO;
import com.triones.api.entity.interlace.dto.InterlaceWalletCurrencyChainDO;
import com.triones.api.entity.interlace.vo.*;
import com.triones.api.service.interlace.InterlaceCryptoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * api - interlace 加密货币相关接口
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/interlace/crypto")
public class ApiInterlaceCryptoController extends BaseController {

    private final InterlaceCryptoService interlaceCryptoService;

    /**
     * 钱包币种列表
     */
    @GetMapping(value = "/wallet/currency/list")
    public R<List<InterlaceBalancesVO>> apiWalletCurrencyList() {
        return R.ok(interlaceCryptoService.apiWalletCurrencyList());
    }

    /**
     * 钱包币种链列表
     */
    @GetMapping(value = "/wallet/currency/chain/list")
    public R<List<InterlaceCurrencyChainVO>> apiWalletCurrencyChainList(@NotBlank(message = "币种不能为空") String currency) {
        return R.ok(interlaceCryptoService.apiWalletCurrencyChainList(currency));
    }

    /**
     * 钱包币种链详情
     */
    @GetMapping(value = "/wallet/currency/chain/{id}")
    public R<InterlaceWalletCurrencyChainDO> apiWalletCurrencyChainDetail(@PathVariable @NotNull(message = "主键不能为空") Long id,@NotBlank(message = "链不能为空") String chain) {
        return R.ok(interlaceCryptoService.apiWalletCurrencyChainDetail(id, chain));
    }

    /**
     * 获取转账手续费及跨链额度
     */
    @RepeatSubmit()
    @PostMapping(value = "/transfers/feeAndQuota")
    public R<CustomInterlaceTransfersFeeAndQuotaVO> transfersFeeAndQuota(@Validated @RequestBody InterlaceTransfersFeeAndQuotaBO bo) {
        return R.ok(interlaceCryptoService.transfersFeeAndQuota(bo));
    }

    /**
     * 转移
     */
    @RepeatSubmit()
    @PostMapping(value = "/transfers")
    public R<Void> transfers(@NotNull(message = "询价id不能为空") Long id) {
        return toAjax(interlaceCryptoService.transfers(id));
    }

    /**
     * 估价询价
     */
    @RepeatSubmit()
    @PostMapping(value = "/estimateQuote")
    public R<InterlaceEstimateQuoteDO> estimateQuote(@Validated @RequestBody InterlaceEstimateQuoteBO bo) {
        return R.ok(interlaceCryptoService.estimateQuote(bo));
    }

    /**
     * 文件上传
     */
    @PostMapping(value = "/updateFile")
    public R<String> updateFile(UploadFileRequest request) {
        return R.ok("操作成功！",interlaceCryptoService.updateFile(request));
    }

    /**
     * 子账号kyc
     */
    @RepeatSubmit()
    @PostMapping(value = "/kyc")
    public R<Void> kyc(@Validated @RequestBody InterlaceKycBO bo) {
        return toAjax(interlaceCryptoService.kyc(bo));
    }

    /**
     * 换汇
     */
    @RepeatSubmit()
    @PostMapping(value = "/convertTrades")
    public R<Void> convertTrades(@NotNull(message = "询价id不能为空") Long id) {
        return toAjax(interlaceCryptoService.convertTrades(id));
    }

    /**
     * 检查是否需要KYC认证
     * true:需要、false:不需要
     */
    @GetMapping("/checkKyc")
    public R<Boolean> checkIsKyc() {
        return R.ok("操作成功！",interlaceCryptoService.checkIsKyc());
    }

    /**
     * 获取kyc信息
     */
    @GetMapping("/kycInfo")
    public R<InterlaceKycVO> kycInfo() {
        return R.ok(interlaceCryptoService.apiKycInfo());
    }

    /**
     * 常用地址列表
     */
    @GetMapping("/blockchainAddressCatalogue")
    public R<List<InterlaceBlockchainAddressCatalogueVO>> blockchainAddressCatalogueList(@NotBlank(message = "币种不能为空") String currency,
                                          @NotBlank(message = "公链不能为空") String chain,
                                          String keyword) {
        return R.ok(interlaceCryptoService.blockchainAddressCatalogueList(currency,chain,keyword));
    }

    /**
     * 量子账户交易列表（分页）
     * type：quote:换汇、transaction:卡交易
     */
    @GetMapping("/internalQuantumTransferPageList")
    public TableDataInfo<CustomInterlaceQuantumTransferVO> internalQuantumTransferPageList(@NotBlank(message = "类型不能为空") String type,
                                                                                     PageQuery pageQuery) {
        return interlaceCryptoService.internalQuantumTransferPageList(type,pageQuery);
    }

    /**
     * 加密货币交易列表（分页）
     */
    @GetMapping("/internalCryptoTransferPageList")
    public TableDataInfo<InterlaceTransfersVO> internalCryptoTransferPageList(@NotBlank(message = "加密货币币种不能为空") String currency,
                                                                              PageQuery pageQuery) {
        return interlaceCryptoService.internalCryptoTransferPageList(currency,pageQuery);
    }

    /**
     * 量子账户交易详情
     */
    @GetMapping("/internalQuantumTransferDetail/{id}")
    public R<CustomInterlaceQuantumTransferVO> internalQuantumTransferDetail(@PathVariable @NotNull(message = "主键不能为空") Long id) {
        return R.ok(interlaceCryptoService.internalQuantumTransferDetail(id));
    }

    /**
     * 加密货币交易详情
     */
    @GetMapping("/internalCryptoTransferPageList/{id}")
    public R<CustomInterlaceTransfersVO> internalCryptoTransferDetail(@PathVariable @NotNull(message = "主键不能为空") Long id) {
        return R.ok(interlaceCryptoService.internalCryptoTransferDetail(id));
    }
}
